package com.jacklon.weblog.web.controller;

import com.jacklon.weblog.common.aspect.ApiOperationLog;
import com.jacklon.weblog.common.enums.ResponseCodeEnum;
import com.jacklon.weblog.common.exception.BizException;
import com.jacklon.weblog.common.utils.JsonUtil;
import com.jacklon.weblog.common.utils.Response;
import com.jacklon.weblog.web.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;


@RestController
@Slf4j
@Api(tags = "首页模块")
public class UserTestController {

    @PostMapping("/admin/userTest")
    @ApiOperationLog(description = "测试接口")
    @ApiOperation(value = "测试接口")
    public Response userTest(@RequestBody @Validated User user) {
        // 打印入参
        log.info(JsonUtil.toJsonString(user));
        // 设置三种日期字段值
        user.setCreateTime(LocalDateTime.now());
        user.setUpdateDate(LocalDate.now());
        user.setTime(LocalTime.now());

        return Response.success(user);
    }

//    @PostMapping("/test")
//    @ApiOperationLog(description = "测试接口2")
//    public Response test(@RequestBody @Validated User user, BindingResult bindingResult) {
//        throw new BizException(ResponseCodeEnum.PRODUCT_NOT_FOUND);
//    }
//
//    @PostMapping("/test3")
//    @ApiOperationLog(description = "测试接口3")
//    public Response test3(@RequestBody @Validated User user, BindingResult bindingResult) {
//       int i = 0 / 1;
//       return Response.success();
//    }
}
